package com.kj.tms.common.utils.calx.sheet;


import com.kj.tms.common.utils.NumberUtils;
import com.kj.tms.common.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ProjectName: ledger
 * @Package: com.hongtu.tms.ledger.calx.factory.sheet
 * @ClassName: Comparator
 * @Description: [对象类型比较]
 * @Author: [zhuyongjie]
 * @CreateDate: 2018/4/18 11:07
 * @UpdateUser: []
 * @UpdateDate: 2018/4/18 11:07
 * @UpdateRemark: []
 * @Version: 1.0
 * Copyright: 北京宏图天安 Copyright (c) 2018
 */
public class Comparator {
    private static Logger logger = LoggerFactory.getLogger(Comparator.class);

    /**
     * @Method      greater
     * @Param		a
     * @Param		b
     * @Return      boolean
     * @Exception
     * @Description [大于比较]
     * @Author      zhuyongjie
     * @Version     1.0
     * @Date        2018/4/18 11:08
     */
    public static boolean greater(Object a, Object b){
        boolean result = false;
        if(a instanceof String && b instanceof String){
            if(NumberUtils.isRealNumber(StringUtil.toString(a))
                    && NumberUtils.isRealNumber(StringUtil.toString(b))){//数字类型比较
                result = (StringUtil.toDouble(a) > StringUtil.toDouble(b));
            }else{
                int to = StringUtil.toString(a).compareTo(StringUtil.toString(b));
                if (to == 1){
                    result = true;
                }
            }//if end
        }else if(a instanceof Number && b instanceof Number){
            result = StringUtil.toDouble(a) > StringUtil.toDouble(b);
        }//if end
//        System.out.println("Comparator.greater("+a+","+b+") calculation result : " + result);
        logger.info("Comparator.greater("+a+","+b+") calculation result : " + result);
        return result;
    }//greater end

    /**
     * @Method      greaterEqual
     * @Param		a
     * @Param		b
     * @Return      boolean
     * @Exception
     * @Description [大于等于判断]
     * @Author      zhuyongjie
     * @Version     1.0
     * @Date        2018/4/18 11:35
     */
    public static boolean greaterEqual(Object a, Object b){
        boolean result = false;
        if(a instanceof String && b instanceof String){
            if(NumberUtils.isRealNumber(StringUtil.toString(a))
                    && NumberUtils.isRealNumber(StringUtil.toString(b))){
                result = (StringUtil.toDouble(a) >= StringUtil.toDouble(b));
            }else{
                int to = StringUtil.toString(a).compareTo(StringUtil.toString(b));
                if (to != -1){
                    result = true;
                }
            }//if end
        }else if(a instanceof Number && b instanceof Number){
            result = StringUtil.toDouble(a) >= StringUtil.toDouble(b);
        }//if end
//        System.out.println("Comparator.greaterEqual("+a+","+b+") calculation result : " + result);
        logger.info("Comparator.greaterEqual("+a+","+b+") calculation result : " + result);
        return result;
    }//greaterEqual end

    /**
     * @Method      less
     * @Param		a
     * @Param		b
     * @Return      boolean
     * @Exception
     * @Description [小于判断]
     * @Author      zhuyongjie
     * @Version     1.0
     * @Date        2018/4/18 11:36
     */
    public static boolean less(Object a, Object b){
        boolean result = false;
        if(a instanceof String && b instanceof String){
            if(NumberUtils.isRealNumber(StringUtil.toString(a))
                    && NumberUtils.isRealNumber(StringUtil.toString(b))){
                result = (StringUtil.toDouble(a) < StringUtil.toDouble(b));
            }else{
                int to = StringUtil.toString(a).compareTo(StringUtil.toString(b));
                if (to == -1){
                    result = true;
                }
            }//if end
        }else if(a instanceof Number && b instanceof Number){
            result = StringUtil.toDouble(a) < StringUtil.toDouble(b);
        }//if end
//        System.out.println("Comparator.less("+a+","+b+") calculation result : " + result);
        logger.info("Comparator.less("+a+","+b+") calculation result : " + result);
        return result;
    }//less end

    /**
     * @Method      lessEqual
     * @Param		a
     * @Param		b
     * @Return      boolean
     * @Exception
     * @Description [小于等于]
     * @Author      zhuyongjie
     * @Version     1.0
     * @Date        2018/4/18 11:11
     */
    public static boolean lessEqual(Object a, Object b){
        boolean result = false;
       if(a instanceof String && b instanceof String){
           if(NumberUtils.isRealNumber(StringUtil.toString(a))
                   && NumberUtils.isRealNumber(StringUtil.toString(b))){
               result = (StringUtil.toDouble(a) <= StringUtil.toDouble(b));
           }else{
               int to = StringUtil.toString(a).compareTo(StringUtil.toString(b));
               if (to != 1){
                   result = true;
               }
           }//if end
       }else if(a instanceof Number && b instanceof Number){
           result = StringUtil.toDouble(a) <= StringUtil.toDouble(b);
       }//if end
//        System.out.println("Comparator.lessEqual("+a+","+b+") calculation result : " + result);
        logger.info("Comparator.lessEqual("+a+","+b+") calculation result : " + result);
        return result;
    }//lessEqual end

    /**
     * @Method      equal
     * @Param		a
     * @Param		b
     * @Return      boolean
     * @Exception
     * @Description [等于判断]
     * @Author      zhuyongjie
     * @Version     1.0
     * @Date        2018/4/18 11:38
     */
    public static boolean equal(Object a, Object b){
        boolean result = false;
        if(a instanceof String && b instanceof String){
            if(NumberUtils.isRealNumber(StringUtil.toString(a))
                    && NumberUtils.isRealNumber(StringUtil.toString(b))){
                result = (StringUtil.toDouble(a) == StringUtil.toDouble(b));
            }else{
                int to = StringUtil.toString(a).compareTo(StringUtil.toString(b));
                if (to == 0 ){
                    result = true;
                }
            }//if end
        }else if(a instanceof Number && b instanceof Number){
            result = StringUtil.toDouble(a) == StringUtil.toDouble(b);
        }//if end
//        System.out.println("Comparator.equal("+a+","+b+") calculation result : " + result);
        logger.info("Comparator.equal("+a+","+b+") calculation result : " + result);
        return result;
    }//equal end

    /**
     * @Method      notEqual
     * @Param		a
     * @Param		b
     * @Return      boolean
     * @Exception
     * @Description [不等于判断]
     * @Author      zhuyongjie
     * @Version     1.0
     * @Date        2018/4/18 11:39
     */
    public static boolean notEqual(Object a, Object b){
        boolean result = false;
        if(a instanceof String && b instanceof String){
            if(NumberUtils.isRealNumber(StringUtil.toString(a))
                    && NumberUtils.isRealNumber(StringUtil.toString(b))){
                result = (StringUtil.toDouble(a) != StringUtil.toDouble(b));
            }else{
                int to = StringUtil.toString(a).compareTo(StringUtil.toString(b));
                if (to != 0 ){
                    result = true;
                }
            }//if end
        }else if(a instanceof Number && b instanceof Number){
            result = StringUtil.toDouble(a) != StringUtil.toDouble(b);
        }//if end
//        System.out.println("Comparator.notEqual("+a+","+b+") calculation result : " + result);
        logger.info("Comparator.notEqual("+a+","+b+") calculation result : " + result);
        return result;
    }//notEqual end
}
